{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.3"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "# 循环嵌套"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "source": [
    "## 打印正三角\n",
    "\n",
    "```\n",
    "*\n",
    "* *\n",
    "* * *\n",
    "* * * *\n",
    "* * * * *\n",
    "```"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "height = int(input('请输入要打印的正三角的高度：'))\n",
    "\n",
    "print('')\n",
    "\n",
    "h = 1\n",
    "width = 1\n",
    "\n",
    "while h <= height:\n",
    "    w = 1\n",
    "    while w <= width:\n",
    "        print('* ', end='')\n",
    "        w += 1\n",
    "\n",
    "    print('')\n",
    "\n",
    "    h += 1\n",
    "    width += 1"
   ]
  },
  {
   "source": [
    "## 打印倒三角\n",
    "\n",
    "```\n",
    "* * * * *\n",
    "* * * *\n",
    "* * *\n",
    "* *\n",
    "* \n",
    "```"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "height = int(input('请输入要打印的倒三角的高度：'))\n",
    "\n",
    "print('')\n",
    "\n",
    "h = 1\n",
    "width = height\n",
    "\n",
    "while h <= height:\n",
    "    w = 1\n",
    "    while w <= width:\n",
    "        print('* ', end='')\n",
    "        w += 1\n",
    "\n",
    "    print('')\n",
    "\n",
    "    h += 1\n",
    "    width -= 1"
   ]
  }
 ]
}